import {
	FINE_GRIT,
	PREMISSIONS_PAGE
} from '@/constant/index.js';

//  全部mixin
export const  globalMixin = {
	computed: {
		/**
		 * @description 用户的细粒度权限判断
		 * @param {Array}
		 * @example {permission(['buttonName'])}
		 * @return {Boole}
		 */
	    permission() {
	      return (value)=>{
			  if (value && value instanceof Array) {
				  let permissionRoles = uni.getStorageSync(FINE_GRIT);
				  console.log(permissionRoles,'permissionRoles')
				  console.log(value,'value')
				  const hasPermission = permissionRoles.some(role => {
				    return value.includes(role)
				  })
				  console.log(hasPermission,'ishasPermission')
				  return hasPermission
			  }else{
				return false
			  }
			 
		  }
	    },
		//是否有页面权限
		pagePermission(){
			return(value)=>{
				if(value)
				{
					 let permissionRoles = uni.getStorageSync(PREMISSIONS_PAGE);
					 const hasPermission = permissionRoles.some(role => {
					   return  role==value
					 })				
					 return hasPermission
				}
				return false
			}
		}
	}
}